/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelAltaSeccion.java
 *
 * Created on 5/05/2012, 01:34:24 AM
 */
package vista.panel;

import controlador.ControladorPrincipal;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import modelo.Seccion;

/**
 *
 * @author Elias Mendoza
 */
public class JPanelAltaSeccion extends javax.swing.JPanel {

  /** Creates new form JPanelAltaSeccion */
  static ControladorPrincipal accion;
  private static JPanelAltaSeccion panelAltaSeccion = null;

  private JPanelAltaSeccion() {
    initComponents();
    accion = new ControladorPrincipal();
 
  }

    public static JPanelAltaSeccion getPanelAltaSeccion() {
        if(panelAltaSeccion == null ){
            panelAltaSeccion = new JPanelAltaSeccion();
        }
        return panelAltaSeccion;
    }

  
  

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabelNumSeccion = new javax.swing.JLabel();
        jLabelColonias = new javax.swing.JLabel();
        jLabelLocalidad = new javax.swing.JLabel();
        jTextFieldNumSeccion = new javax.swing.JTextField();
        jTextFieldColonias = new javax.swing.JTextField();
        jTextFieldLocalidad = new javax.swing.JTextField();
        jButtonRegistrar = new javax.swing.JButton();
        jButtonBorrar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPaneRegistro = new javax.swing.JTextPane();

        setBackground(new java.awt.Color(255, 255, 255));
        setLayout(new java.awt.GridBagLayout());

        jLabelNumSeccion.setFont(new java.awt.Font("Maiandra GD", 1, 12));
        jLabelNumSeccion.setText("Numero de Sección:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(20, 13, 0, 0);
        add(jLabelNumSeccion, gridBagConstraints);

        jLabelColonias.setFont(new java.awt.Font("Maiandra GD", 1, 12));
        jLabelColonias.setText("Colonias: ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(17, 13, 0, 0);
        add(jLabelColonias, gridBagConstraints);

        jLabelLocalidad.setFont(new java.awt.Font("Maiandra GD", 1, 12));
        jLabelLocalidad.setText("Localidad:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(17, 13, 0, 0);
        add(jLabelLocalidad, gridBagConstraints);

        jTextFieldNumSeccion.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jTextFieldNumSeccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldNumSeccionKeyTyped(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 42;
        gridBagConstraints.ipady = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(18, 14, 0, 0);
        add(jTextFieldNumSeccion, gridBagConstraints);

        jTextFieldColonias.setFont(new java.awt.Font("Times New Roman", 1, 12));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 292;
        gridBagConstraints.ipady = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(15, 14, 0, 0);
        add(jTextFieldColonias, gridBagConstraints);

        jTextFieldLocalidad.setFont(new java.awt.Font("Times New Roman", 1, 12));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 92;
        gridBagConstraints.ipady = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(15, 14, 0, 0);
        add(jTextFieldLocalidad, gridBagConstraints);

        jButtonRegistrar.setFont(new java.awt.Font("Maiandra GD", 1, 12));
        jButtonRegistrar.setText("Registrar");
        jButtonRegistrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegistrarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 4;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(12, 1, 16, 0);
        add(jButtonRegistrar, gridBagConstraints);

        jButtonBorrar.setFont(new java.awt.Font("Maiandra GD", 1, 12));
        jButtonBorrar.setText("Borrar");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 5;
        gridBagConstraints.ipady = 7;
        gridBagConstraints.insets = new java.awt.Insets(12, 1, 16, 5);
        add(jButtonBorrar, gridBagConstraints);

        jLabel1.setFont(new java.awt.Font("Calibri", 1, 18));
        jLabel1.setText("Registrar nueva Sección");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 20;
        add(jLabel1, gridBagConstraints);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Ult. Registro", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 10))); // NOI18N

        jTextPaneRegistro.setBorder(null);
        jTextPaneRegistro.setEditable(false);
        jTextPaneRegistro.setFont(new java.awt.Font("Tahoma", 0, 10));
        jScrollPane1.setViewportView(jTextPaneRegistro);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 4;
        gridBagConstraints.ipadx = 150;
        gridBagConstraints.ipady = 100;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 6, 0);
        jPanel1.add(jScrollPane1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 4;
        gridBagConstraints.insets = new java.awt.Insets(6, 18, 5, 11);
        add(jPanel1, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

  private void jButtonRegistrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegistrarActionPerformed
    // TODO add your handling code here:
    JTextField[] campos = {jTextFieldColonias, jTextFieldLocalidad, jTextFieldNumSeccion};
    if (!accion.camposVacios(campos)) {
      Seccion seccion = new Seccion();
      seccion.setNumero(Integer.parseInt(jTextFieldNumSeccion.getText()));
      seccion.setColonias(jTextFieldColonias.getText());
      seccion.setLocalidad(jTextFieldLocalidad.getText());
      

      accion.registrar(seccion, 2, jTextPaneRegistro);
    }
  }//GEN-LAST:event_jButtonRegistrarActionPerformed

  private void jTextFieldNumSeccionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNumSeccionKeyTyped
    // TODO add your handling code here:
    if (!accion.compruebaCaracterNumero((int) evt.getKeyChar())) {
      evt.setKeyChar((char) KeyEvent.VK_CLEAR);
    }
  }//GEN-LAST:event_jTextFieldNumSeccionKeyTyped
// public void paint(Graphics g) {
//    Image imagen = new ImageIcon(getClass().getResource("/vista/img/fondo_for.png")).getImage();
//    g.drawImage(imagen, 0, 0, getWidth(), getHeight(), null);
//    setOpaque(false);
//    super.paintComponent(g);
//  }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton jButtonBorrar;
    public javax.swing.JButton jButtonRegistrar;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JLabel jLabelColonias;
    public javax.swing.JLabel jLabelLocalidad;
    public javax.swing.JLabel jLabelNumSeccion;
    public javax.swing.JPanel jPanel1;
    public javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTextField jTextFieldColonias;
    public javax.swing.JTextField jTextFieldLocalidad;
    public javax.swing.JTextField jTextFieldNumSeccion;
    public javax.swing.JTextPane jTextPaneRegistro;
    // End of variables declaration//GEN-END:variables
}
